﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace VmcRemote.PpcRemote
{
    public partial class MouseForm : Form
    {
        Point start;
        Point end;
        Point lastSent;

        public MouseForm()
        {
            InitializeComponent();
        }

        private void RefreshAll()
        {
            timer1.Enabled = false;
            Refresh();
            panel1.Refresh();
            pictureBox1.Refresh();
        }

        private void MouseForm_MouseDown(object sender, MouseEventArgs e)
        {
            RefreshAll();
            start.X = e.X;
            start.Y = e.Y;
            lastSent.X = e.X;
            lastSent.Y = e.Y;
        }

        private void MouseForm_MouseMove(object sender, MouseEventArgs e)
        {
            end.X = e.X;
            end.Y = e.Y;
            Graphics g = CreateGraphics();
            g.DrawLine(new Pen(Color.Black), lastSent.X, lastSent.Y, end.X, end.Y);
            label1.Text = string.Format("Move: {0},{1} to {2},{3}", start.X, start.Y, end.X, end.Y);
            lastSent.X = end.X;
            lastSent.Y = end.Y;
        }

        private void MouseForm_MouseUp(object sender, MouseEventArgs e)
        {
            timer1.Enabled = true;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void leftClickButton_Click(object sender, EventArgs e)
        {

        }

        private void rightClickButton_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            timer1.Enabled = false;
            RefreshAll();
            start.X = (int)(0.5 * pictureBox1.Width);
            start.Y = e.Y;
            lastSent.X = e.X;
            lastSent.Y = e.Y;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            pictureBox1.Refresh();
            end.X = start.X;
            end.Y = e.Y;
            Graphics g = pictureBox1.CreateGraphics();
            g.DrawLine(new Pen(Color.White), start.X, start.Y, end.X, end.Y);
            label1.Text = string.Format("VScroll: {0} to {1}", start.Y, end.Y);
            lastSent.X = end.X;
            lastSent.Y = end.Y;
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            timer1.Enabled = true;
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            timer1.Enabled = false;
            RefreshAll();
            start.X = e.X;
            start.Y = (int)(0.5 * panel1.Height);
            lastSent.X = e.X;
            lastSent.Y = e.Y;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            panel1.Refresh();
            end.X = e.X;
            end.Y = start.Y;
            Graphics g = panel1.CreateGraphics();
            g.DrawLine(new Pen(Color.White), start.X, start.Y, end.X, end.Y);
            label1.Text = string.Format("HScroll: {0} to {1}", start.X, end.X);
            lastSent.X = end.X;
            lastSent.Y = end.Y;
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            RefreshAll();
        }
    }
}